import { useState } from 'react'
import * as server from '../../services/tools'
import { message } from 'antd'

function useQueryUnionId(initVal = '') {
  const [val, setVal] = useState(initVal)
  const [loading, setLoading] = useState(false)

  const search = ({ openId }) => {
    setLoading(true)
    server.queryUnionIdByOpenId({ openId: openId }).then((res) => {
      setLoading(false)
      if (res.code === '0' && res.data && res.data.unionid) {
        setVal(res.data.unionid)
      } else {
        setVal('')
        message.warning('unionid获取异常')
      }
    })
  }
  return { val, search, loading }
}


export {
  useQueryUnionId
}
